<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>记账本</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/bootstrap-icons-1.11.3/font/bootstrap-icons.css" rel="stylesheet">
  </head>
  <body>
    <div class="container-sm border mt-3 mb-3">
      <h1 class="text-center">记账本</h1>
      <button type="button" class="btn btn-primary mb-3" onclick="jumpAdd()"><i class="bi bi-plus-lg"></i> 添加</button>
      <% accounts.forEach(item => { %>
      <div class="card mb-3">
        <div class="card-header <%= item.type === 1 ? 'bg-success-subtle' : 'bg-danger-subtle' %>">
          <div class="row justify-content-between">
            <div class="col-auto"><%= item.time %></div>
            <div class="col-auto">
              <button type="button" class="btn-close" aria-label="Close" onclick="deleteAccount('<%= item._id %>')"></button>
            </div>
          </div>
        </div>
        <div class="card-body">
          <div class="row align-items-center">
            <div class="col-sm-6">
              <h5 class="card-title mb-0"><%= item.title %></h5>
            </div>
            <div class="col-sm-2">
              <span class="badge <%= item.type === 1 ? 'text-bg-success' : 'text-bg-warning' %>"><%= item.type === 1 ? '收入' : '支出' %></span>
            </div>
            <div class="col-sm-4">
              <p class="card-text"><%= item.account %>元</p>
            </div>
          </div>
          <div class="alert alert-light mt-3 mb-0" role="alert">
            <%= item.remark %>
          </div>
        </div>
      </div>
      <% }) %>
    </div>
    <script src="/js/bootstrap.bundle.min.js"></script>
    <script>
      function jumpAdd() {
        location.href = '/add'
      }

      function deleteAccount(id) {
        if(confirm('您确定要删除吗？')) {
          location.href = `/delete/${id}`
        }
      }
    </script>
  </body>
</html>